package com.demohomework.homeworkdemo.service.impl;

import com.demohomework.homeworkdemo.mapper.AssignmentMapper;
import com.demohomework.homeworkdemo.pojo.Assignment;
import com.demohomework.homeworkdemo.service.AssignmentService;
import com.demohomework.homeworkdemo.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class AssignmentServiceImpl implements AssignmentService {
    @Autowired
    private AssignmentMapper assignmentMapper;

    @Override
    public List<Assignment> list() {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        return assignmentMapper.list(id);
    }

    @Override
    public void add(Assignment assignment) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        assignment.setTeacherId(id);
        assignmentMapper.add(assignment);
    }

    @Override
    public Assignment findId(Integer id) {
        Assignment a = assignmentMapper.findId(id);
        return a;
    }

    @Override
    public void update(Assignment assignment) {
        assignmentMapper.update(assignment);
    }

    @Override
    public void delete(Assignment assignment) {
        assignmentMapper.delete(assignment);
    }

    @Override
    public List<Assignment> listByCourseId(Integer courseId) {
        return assignmentMapper.listByCourseId(courseId);
    }

    @Override
    public void deleteById(int id) {
        assignmentMapper.deleteById(id);
    }


}
